(function(){
	$.showBox = function(id, callback, e, isHide) {
		var html = $('#' + id).html();
		var curObj;

		var cover = function() {
			var chtml = '<div id="cover" style="width: 100%; height: 100%; position: fixed; z-index: 1000; top: 0px; left: 0px; overflow: hidden;"><div style="height: 100%; filter:alpha(opacity = 30);-moz-opacity: 0.3;	-khtml-opacity: 0.3;opacity: 0.3; z-index: 10008; background: rgb(0, 0, 0);"></div></div>';
			if($('#cover').length < 1) {
				$('body').append(chtml);
			}
			$('#cover').fadeIn(200);
			return $('#cover');
		}

		var setPop = function(obj) {
			cover();
			$(obj).fadeIn(200);
			obj.style.margin = 0;
			if (window.navigator.userAgent.toUpperCase().indexOf('MSIE 6') != -1) {
				// 如果是IE6
				obj.style.position = 'absolute';

				function setPopInIE6() {
					obj.style.left = parseInt((document.documentElement.scrollLeft || document.body.scrollLeft) + (document.documentElement.clientWidth - obj.offsetWidth) / 2) + 'px';
					obj.style.top = parseInt((document.documentElement.scrollTop || document.body.scrollTop) + (document.documentElement.clientHeight - obj.offsetHeight) / 2) + 'px';
				}

				function addEvent(node, type, listener) {
					node['e' + type + listener] = listener;
					node[type + listener] = function() {
						node['e' + type + listener](window.event);
					}
					node.attachEvent('on' + type, node[type + listener]);
				}

				setPopInIE6();
				addEvent(window, 'resize', setPopInIE6);
				addEvent(window, 'scroll', setPopInIE6);
			} else {
				// 如果是非IE6
				obj.style.position = 'fixed';
				obj.style.left = '50%';
				obj.style.top = '50%';
				obj.style.margin = -parseInt(obj.offsetHeight / 2) + 'px 0 0 ' + -parseInt(obj.offsetWidth / 2) + 'px';
			}
		}

		var hidePop = function() {
			!isHide && cover().fadeOut(200);
			curObj.fadeOut(200);
		}

		var addMsg = function() {
			if (typeof(callback) != 'function') {
				e && curObj.find(e).html(callback);
			} else if (e.data('popData')) {
				var popData = e.data('popData')
				for(var p in popData) {
					if($('.'+p).data('settime')) {
						var time = popData[p];
						var timer = setInterval(function() {
							$('.'+p).text('（'+(--time)+'）');
							if(time <= 0) {
								clearInterval(timer);
								$('.'+p).data('clickable', true).text('');
							}
						}, 1000);
					} else {
						$('.'+p)[$('.'+p)[0].nodeName == 'INPUT'?'val':'text'](popData[p]);
					}
				}
			}
		}

		var cancelListener = function(event) {
			event.preventDefault();
			hidePop();
		}

		var confirmListener = function(event) {
			event.preventDefault();
			if (typeof(callback) == 'function') {
				callback(e, hidePop);
			};
		}

		if(!html && id == 'pop-check-input') {
			html = '<div class="pop check-input-pop" data-id="pop-check-input"><a href="" class="close-btn cancel">×</a><p></p></div>';
		}

		if ($('div[data-id=' + id + ']').length < 1) {
			$('body').append(html);
			curObj = $('div[data-id=' + id + ']');
			if(!curObj) {
				window.console && console.log('==== error ===没有'+id+'弹窗，请查看代码======');
				return;
			}
			addMsg();
			setPop(curObj[0]);
			curObj.find('.cancel').bind('click', cancelListener);
			curObj.find('.confirm').bind('click', confirmListener);
		} else {
			curObj = $('div[data-id=' + id + ']');
			if(!curObj) {
				window.console && console.log('==== error ===没有'+id+'弹窗，请查看代码======');
				return;
			}
			addMsg();
			setPop(curObj[0]);
			curObj.find('.cancel').unbind('click');
			curObj.find('.confirm').unbind('click');
			curObj.find('.cancel').bind('click', cancelListener);
			curObj.find('.confirm').bind('click', confirmListener);
		}
		console.log(curObj);
		isHide && cover().delay(5000).fadeOut(200) && curObj.delay(5000).fadeOut(200);
    }
	
})();


